package com.lwh.ssl;

import javax.net.ssl.SSLContext;
import java.io.IOException;
import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.UnrecoverableKeyException;
import java.security.cert.CertificateException;

/**
 * @Description: qzt ssl 构建工厂
 * @Date: 2019-09-12
 * @author: luowuhui
 */
public class QztSslContextFactory {

	public static SSLContext buindSSLContext (QztSsl qztSsl) throws IOException, UnrecoverableKeyException, CertificateException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException {
		TrustStrategy qztTrustStrategy = new QztTrustStrategy(qztSsl.trustStoreURL());
		SSLContext sslContext = new SSLContextBuilder().loadKeyMaterial(qztSsl.keyStoreURL(),qztSsl.storeKeyPass(),qztSsl.keyPass())
		                                               .loadTrustMaterial(qztTrustStrategy)
		                                               .build();
		return sslContext;
	}
}
